<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:81:"E:\wamp\www\dataerqi\626\tp5\public/../application/index\view\Carousel\index.html";i:1499045231;}*/ ?>
<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>轮播图</title>
    <!-- LOGO -->
    <link rel="Shortcut Icon" href="/static/zwb/img/safe.jpg"/>
    <!--加载CSS-->
    <link rel="stylesheet" type="text/css" href="/static/home/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/home/css/reset.css" />
</head>
<body>

<div class="row mt50">
    <div class="col-md-12">
        <table class="table table-hover bg-info ">
            <tr >
                <th>id</th>
                <th>新闻标题</th>
                <th>新闻图片</th>
                <th>显示</th>
                <th>封面</th>
                <th>操作</th>

                <th><a href="/addCarousel/" class="btn btn-primary btn-xs">添加</a></th>

            </tr>
                <?php if(is_array($file) || $file instanceof \think\Collection || $file instanceof \think\Paginator): $i = 0; $__LIST__ = $file;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$li): $mod = ($i % 2 );++$i;?>
            <tr>
                <td><?php echo $li['id']; ?></td>
                <td><?php echo $li['aname']; ?></td>
                <td ><img src="<?php echo $li['cmage']; ?>" alt="" style="width: 100px"></td>
                <td class="xianshi">
               <?php if($li['display'] == 0): ?>
                    <button type="" da="<?php echo $li['id']; ?>" class="xian" style="display: none;color: blue">显示</button>
                    <button type="" da="<?php echo $li['id']; ?>" class="noxian" style="color: blue">不显示</button>
                    <?php else: ?>
                    <button type="" da="<?php echo $li['id']; ?>" class="xian" style="color: blue">显示</button>
                    <button type="" da="<?php echo $li['id']; ?>" class="noxian" style="display: none;color: blue">不显示</button>
                <?php endif; ?>
                </td>
                <td>
                <?php if($li['home'] == 1): ?> 
                    <button ><a href="/addCarf/<?php echo $li['id']; ?>" style="color: blue">非封面</a></button>
                  <?php else: ?>
                    <button ><a href="/addCarfe/<?php echo $li['id']; ?>" style="color: blue">封面</a></button>
                <?php endif; ?>
                </td>
                <td><?php echo date("Y-m-d H:i",$li['regtime']); ?></td>
                <td class="col-md-2">
                    <button data-id="<?php echo $li['id']; ?>" class="btn btn-danger btn-xs del-btn">删除</button>
                </td>
            </tr>
                <?php endforeach; endif; else: echo "" ;endif; ?>
        </table>
    </div>
</div>
    <script type="text/javascript" src="/static/home/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/home/js/bootstrap.js"></script>
    <script type="text/javascript" src="/static/home/layui/layui.js"></script>

<script>
     $(function () {
        // 触发用户删除
        $('.del-btn').click(function () {
            var ac_id = $(this).attr('data-id');
            console.log('删除的ID为:', ac_id);

            if (confirm('您确定要 [ 删 除 ] 该图片么?')) {
                var obj = $(this).parents('tr');
                // console.log(obj);
                delAjax(ac_id, obj);// 执行删除操作
            }
        });
    });
         // 执行AJAX删除的操作
    function delAjax(aid,obj) {
        // console.log(id);
        $.ajax({
            type: 'get',
            url: '/addCar/' + aid,
            dateType: 'json',
            success: function (data) {
                if (data > 0) {
                    obj.remove();
                } else {
                    console.log('删除失败');     
                }
            },
            error: function () {
                // AJAX执行失败
                alert('ajax操作失败');
            }
        });
        }


        //显示
        $(function(){
            $('.noxian').click(function(){
                $id = $(this).attr('da');
                $list = $(".xian"+'[da = '+$id+']');
                console.log($list);
                var _this = this;
                $.ajax({
                    type:'get',
                    url: '/addplay/'+$id,
                    dataType: 'json',   
                    success:function(data){
                        // console.log(data);
                            if ( data > 0) {
                                $($list).css("display","block");
                                $(_this).css("display","none"); 
                            }
                       },
                    error: function(){
                            alert('更换失败');
                    }
                });
                
            })
        })
        //不显示
        $(function(){
            $('.xian').click(function(){
                $id = $(this).attr('da');
                $list = $(".noxian"+'[da = '+$id+']');
                console.log($list);
                var _this = this;
                $.ajax({
                    type:'get',
                    url: '/addplayn/'+$id,
                    dataType: 'json',   
                    success:function(data){
                        // console.log(data);
                            if ( data > 0) {
                                $($list).css("display","block");
                                $(_this).css("display","none"); 
                            }
                       },
                    error: function(){
                            alert('更换失败');
                    }
                });
                
            })
        })
</script>
</body>
</html>
